package com.changgou.web.gateway.filter;

/**
 * @author kfzhao
 * @version 1.0
 * @className UrlFilter
 * @description
 * @date 2022/1/2 22:01
 */
public class UrlFilter {

    /**
     * 所有需要传递令牌的地址
     */
    public static String filterPath = "/api/wseckillorder/**,/api/seckillgoods/**,/api/seckillorder/**,/api/wseckillgoods/**," +
            "/api/wxpay,/api/wxpay/**,/api/worder/**,/api/us" +
            "er/**,/api/address/**,/api/wcart/**,/api/cart/**,/api/categoryReport/**,/api/ord" +
            "erConfig/**,/api/order/**,/api/orderItem/**,/api/orderLog/**,/api/preferential/*" +
            "*,/api/returnCause/**,/api/returnOrder/**,/api/returnOrderItem/**";

    /**
     * 判断用户正在访问的url地址是否存在于filterPath中
     *
     * @param url
     * @return boolean
     * @throws
     * @description
     * @author kfzhao
     * @date 2022/1/2 22:03
     */
    public static boolean hasAuthorize(String url) {
        String[] split = filterPath.replace("**", "").split(",");
        for (String value : split) {
            if (url.startsWith(value)) {
                // 当前的访问地址需要传递令牌
                return true;
            }
        }
        // 当前的访问地址不需要传递令牌
        return false;
    }
}
